<cfcomponent displayname="JsminJsCompressor" extends="AbstractCompressor" output="false" hint="Compresses JavaScript using JSMin">
	
	<cffunction name="init" access="public" returntype="AbstractCompressor" output="false">
		<cfargument name="javaLoader" type="any" required="false" default="" hint="a JavaLoader instance. If provided, this should be used to load the Java objects; if not provided, Java objects shouldbe instantiated via createObject()" />
		<cfargument name="jarPath" type="string" required="false" default="" hint="path of the directory where the .jar files are located" />
		
		<cfscript>
		var aJarPaths = arrayNew(1);
			
		if( isObject(arguments.javaLoader) AND len(arguments.jarPath) )
		{
			/*
				load external .jar classes using JavaLoader
			*/
			
			arrayAppend( aJarPaths, arguments.jarPath & '/jsmin.jar' );
			
			arguments.javaLoader.init( aJarPaths );		
			
			variables.jJSMin = arguments.javaLoader.create("com.magnoliabox.jsmin.JSMin");
		}
		else
		{
			/*
				assume external .jars are already available (in the classpath)
			*/
			
			variables.jJSMin = createObject("java","com.magnoliabox.jsmin.JSMin");
		}
		
		variables.jOutputStream = createObject("java","java.io.ByteArrayOutputStream");
		variables.jStringReader = createObject("java","java.io.StringReader");
		
		super.init(argumentCollection=arguments);
		
		return this;
		</cfscript>
		
	</cffunction>
	
	<cffunction name="compressString" access="public" returnType="string" hint="takes a js string and minifies it using JSMin">
		<cfargument name="sInput" type="string" required="true" />
		<cfscript>
		var sOut = arguments.sInput;
			
		var joOutput = variables.jOutputStream.init();
		var joInput = variables.jStringReader.init(sOut);
		var joJSMin = variables.jJSMin.init(joInput, joOutput);
		
		joJSMin.jsmin();
		joInput.close();
		sOut = joOutput.toString();
		joOutput.close();
		
		return sOut;
		</cfscript>
	</cffunction>
	
</cfcomponent>
